import { Injectable, Inject } from "@angular/core";
import { Actions } from "@ngrx/effects";
import { ILoginRequest } from "@/user/store/models/user";
import {
  CanActivate,
  ActivatedRouteSnapshot,
  RouterStateSnapshot
} from "@angular/router";

import { Store, select } from "@ngrx/store";
import * as fromUser from "@/user/store/reducers/index";
import * as fromRoot from "@/reducers/index";
import { Subscription, Subject, Observable, of } from "rxjs";
import { UserActions } from "@/user/store/actions";
import { combineAll, debounceTime } from "rxjs/operators";
import {
  catchError,
  exhaustMap,
  map,
  tap,
  filter,
  take,
  skip
} from "rxjs/operators";

@Injectable({
  providedIn: "root"
})
export class AuthService {
  isLogin$ = this.store.pipe(
    select(fromRoot.userRes),
    filter(e => e.code !== -1),
    map(e => e.code === 200)
  );
  constructor(
    @Inject("UserService") private userService,
    private store: Store<fromUser.State | fromRoot.State>
  ) {}
  // ...
  public hasAuth(user: any): boolean {
    // Check whether the token is expired and return
    // true or false
    return !!user;
  }
}
